package com.project.class3_29.annotation;

import java.lang.reflect.Field;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        Class manClass = Man.class;
        //判断指定类中，是否有MyAnnotation注解
        if(manClass.isAnnotationPresent(MyAnnotation.class)){
            //得到指定类的注解对象
            MyAnnotation my = (MyAnnotation)manClass.getAnnotation(MyAnnotation.class);
            //得到注解元素的值
            System.out.println(my.name()+"   "+my.age()+"   "+ Arrays.toString(my.array()));
        }

        try {
            //得到id属性对象
           Field f =  manClass.getDeclaredField("id");
           if(f.isAnnotationPresent(MyAnnotation.class)){
               MyAnnotation my = f.getAnnotation(MyAnnotation.class);
               System.out.println(my.name()+"   "+my.age()+"   "+ Arrays.toString(my.array()));
           }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
